import request from "@/router/axios";

export const updateSensorCapacity = (id) => {
  return request({
    url: "/api/uic-system/fillmachine/refreshSensorWaterlep",
    method: "get",
    params: { id },
  });
};

export const getSyncAll = async () => {
  return await request({
    url: "/api/uic-system/fillmachine/all",
    method: "get",
    params: {
      onlyViewWarnMachine: true,
    },
  });
};

export const getAllBySearch = (params) => {
  return request({
    url: "/api/uic-system/fillmachine/all",
    method: "get",
    params,
  });
};

export const getPage = (page, params) => {
  return request({
    url: "/admin/machine/page",
    method: "get",
    params: {
      ...page,
      ...params,
    },
  });
};
export const getPagemachinestoragewater = (page, params) => {
  return request({
    url: "/admin/machinestoragewater/page",
    method: "get",
    params: {
      ...page,
      ...params,
    },
  });
};
export const summarymachinestoragewater = () => {
  return request({
    url: "/admin/machinestoragewater/summary",
    method: "get",
  });
};

export const saveOrUpdate = (form) => {
  return request({
    url: "/admin/machine/submit",
    method: "post",
    data: {
      ...form,
    },
  });
};
export const updateFillingMachine = (form) => {
  return request({
    url: "/api/uic-system/fillmachine/updateFillingMachine",
    method: "post",
    data: {
      ...form,
    },
  });
};

export const getDeviceNetworkSignal = (machineId) => {
  return request({
    url: `/api/uic-system/fillmachine/getDeviceNetworkSignal?id=${machineId}`,
    method: "get",
  });
};

export const getQRCode = (id) => {
  return request({
    url: "/api/uic-system/fillmachine/getQRCode",
    method: "get",
    responseType: "blob",
    header: {
      Accept: "image/png",
    },
    params: { id },
  });
};

export const getQRCode2 = (id) => {
  return request({
    url: "/api/uic-system/fillmachine/getQRCode",
    method: "get",
    params: { id },
  });
};

export const detailById = (id) => {
  return request({
    url: "/api/uic-system/fillmachine/detailById",
    method: "get",
    params: { id },
  });
};

// 安装记录
export const installRecordPage = (page, params) => {
  return request({
    url: "/api/uic-system/fillmachineinstallrecord/page",
    method: "get",
    params: {
      ...page,
      ...params,
    },
  });
};

export const installFillingMachine = (form) => {
  return request({
    url: "/api/uic-system/fillmachineinstallrecord/submit",
    method: "post",
    data: {
      ...form,
    },
  });
};

export const batchUpdateUreaPrice = (data) => {
  return request({
    url: "/admin/machine/batchUpdateUreaPrice",
    method: "post",
    data,
  });
};

export const getListByTeamId = (teamId) => {
  return request({
    url: "/api/uic-system/fillmachine/list",
    method: "get",
    params: {
      size: 500,
      teamId,
    },
  });
};

// 余量汇总
export const summary = () => {
  return request({
    url: "/api/uic-system/fillmachinestoragewater/summary",
    method: "get",
  });
};

// 余量校准
export const adjust = (data) => {
  return request({
    url: "/api/uic-system/fillmachinestoragewater/save",
    method: "post",
    data,
  });
};

// 余量历史
export const getAdjustHistoryPage = (page, params) => {
  return request({
    url: "/api/uic-system/fillmachinestoragewater/page",
    method: "get",
    params: {
      ...page,
      ...params,
    },
  });
};

export const detailFromIotByMacCode = (macCode, supplierName) => {
  return request({
    url: "/admin/machine/detailFromIotByMacCode",
    method: "get",
    params: {
      macCode,
      supplierName,
    },
  });
};

export const getDeviceIsOnline = (macCode) => {
  return request({
    url: "/api/uic-system/fillmachine/getDeviceIsOnline",
    method: "get",
    params: {
      macCode,
    },
  });
};

export const syncBasicAttrByMacCode = (macCode) => {
  return request({
    url: "/api/uic-system/fillmachine/syncBasicAttrByMacCode",
    method: "get",
    params: {
      macCode,
    },
  });
};

export const shareBucket = (ids) => {
  return request({
    url: "/api/uic-system/fillmachine/shareBucket",
    method: "post",
    params: {
      ids,
    },
  });
};
export const separateBucket = (ids) => {
  return request({
    url: "/api/uic-system/fillmachine/separateBucket",
    method: "post",
    params: {
      ids,
    },
  });
};
